<template>
	<view class="con">
		<view class="conTopimg">
			<image :src="cateInfo.img_url"></image>
		</view>
		<view class="types">
			<view class="typesleft">
				<block  v-for="(item,index) in changeList">
					<view :class="['typesleftli', tabindex == index ? 'oncolor': '']" @click="changeStatus(item,index)">
						<text>{{item.name}}</text>
						<text class="xian"></text>
					</view>
				</block>
			</view>
				<view class="typesright" >
					<view class="typesneri">
						<view class="typestwo">
							<!-- <view class="typestwobt">{{name}}</view> -->
							<view class="typestwocont" v-if="!isZanwu" >
								<view class="ttcontli" v-for="(v,i) in twolit">
									<view class="ttcontliimg" @click="ontype(v)">
										<image :src="v.preview_img" mode="scaleToFill"></image>
									</view>
									<view class="ttcontlitext" @click="ontype(v)">
										<view class="title">
											<text>{{v.product_name}}</text>
											<!-- <block v-if="v.is_user_member == 0">
												<text class="discount red">{{v.goods_price_msg}}</text>
											</block>
											<block v-else-if="v.is_user_member > 0">
												<text class="hyj" v-if="v.goods_price_msg">{{v.goods_price_msg}}</text>
											</block> -->
											
										</view>
										<view class="price">
											<view class="red">
												￥<text>{{v.local_shop_price}}</text>
											</view>
											<view class="huaxian">
												￥<text>{{v.market_price}}</text>
											</view>
										</view>
										
									</view>
									<view class="buy" @click="onGwc(v)">
										<image src="https://img-cdn.duobashuzi.com/xianggui/img/gwc_h.png" mode="scaleToFill"></image>
										<text class="num" v-if="v.mum">{{v.mum}}</text>
									</view>
								</view>
								
							</view>
							<view class="zwFenlei" v-else>
								<image src="https://img-cdn.duobashuzi.com/xianggui/img/zwfl.png" mode="scaleToFill"></image>
								<view class="zwFenleiTex">该分类下面暂无商品</view>
							</view>
						</view>
						
					</view>
				</view>
		</view>
		<side-bar></side-bar>
		<sheet-bottom ref="getSpecList" :isCart="isCart" @goodsId="jianting" :isSheet.sync="isSheet" :goodsInfo.sync="goodsInfo" @closeSheet="closeShee"></sheet-bottom>
	</view>

</template>

<script>
	import{topCate,getChildrenCateList,goodsDetail} from '@/api/index.js'
	import sheetBottom from "@/components/sheet/sheetBottom.vue"
	import sideBar from "@/components/sheet/sideBar.vue"
	import {getUserInfo} from '@/api/my.js'
	export default {
		data() {
			return {
				isCart:0,
				isSheet:false,
				tabindex:0,
				goodsInfo:'',
				changeList: [
					{id: 0,title: '商务办公'},
					{id: 1,title: '商务办公'},
					{id: 2,title: '商务办公'},
					{id: 3,title: '商务办公'}
				],
				twolit:[],
				isZanwu:false,
				cateInfo:{
					img_url:'https://img-cdn.duobashuzi.com/storage/images/20250221/l1LfmGKBGkPyWrKXLr2QLbAxNlvVnDwcZtkWgye4.png'
				},
				name:''
			}
		},
		components:{
			sheetBottom,
			sideBar
		},
		watch: {
			"goodsInfo"(newVal, old) {
				console.log(newVal)
			}
		},
		onLoad(options) {
			this.gettopCate();
			uni.$on('goodsId',function(res){
			  console.log(res)
			});
			this.getInfo()
		},
		onShow() {
			this.twolit.forEach((v,i)=>{
					v.mum = 0;
			});
		},
		methods: {
			getInfo(){
				getUserInfo({}).then(res=>{
					uni.setStorageSync('memberLevel',res.data.member_level)
				})
			},
			//分类的跳转
			ontype(e){
				console.log(e)
			// let data = this.baseList[e];
				uni.navigateTo({
					url: '/package/info/index?id='+e.id+'&title='+e.product_name
				});
			},
			// 分类接口
			gettopCate(){
				topCate({}).then(res => {
					console.log(res)
					 this.changeList = res.result;
					 this.name = this.changeList[0].name
					 this.getChildrenCateList(this.changeList[0].id)
				}).catch(err => {
					console.log(err)
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
			},
			//获取子级分类
			getChildrenCateList(a){
				getChildrenCateList({"cate_pid":a}).then(res => {
					console.log(res)
					
					if(res.result.goodsList.length === 0){
						this.isZanwu=true;
						this.twolit = [];
						this.cateInfo = res.result.cateInfo;
					}else{
						this.twolit = res.result.goodsList;
						this.cateInfo = res.result.cateInfo;
						this.isZanwu=false;
					}
					 
					 
				}).catch(err => {
					console.log(err)
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
			},
			changeStatus(e,i){
				this.tabindex = i;
				this.name = this.changeList[i].name
			
				this.getChildrenCateList(e.id)
			},
			handleGoods(act_id){
				console.log(act_id)
				uni.navigateTo({
					url:"/pages/goodsList/index?act_id="+act_id
				})
			},
			getAdList() {
				const openid = uni.getStorageSync('openid')
				const shCode = uni.getStorageSync('shCode')
				adList({openid,shCode,aaa:123}).then(res => {
					
					this.actList = res.data
				}).catch(err => {
					console.log(err)
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
			},
			getGoodsList(){
				goodsList().then(res=>{
					this.goodsList = res.data
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
			},
			getStatus(e) {
				this.isLogin = e
			},
			toDetail() {
				uni.navigateTo({
					url: "/package/info/index"
				})
			},
			//监听加入购物车成功
			jianting(e){
				this.twolit.forEach((v,i)=>{
					if(v.id == e.id){
						
						v.mum = e.minimum_order_quantity;
					}
				});
			},
			//打开购买弹窗
			onGwc(e){
				console.log()
				goodsDetail({
					goods_id: e.id
				}).then(res => {
					console.log(res)
					this.isSheet = true;
					this.goodsInfo = res.result;
					if(this.goodsInfo.is_spec == 1){
						this.$nextTick(()=>{
							this.$refs.getSpecList.getgoodsSpecList();
						})
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
				
				console.log(this.goodsInfo)
				// this.$set(e,"goods_num",0)
			},
			//关闭购物车
			closeShee(e){
				this.isSheet = e
			}
		}
	}
</script>

<style lang="scss">
	@import 'index.scss';
</style>